home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / adscraper.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  1.8 KB  |  49 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import re
  5.  
  6. def purify(data):
  7.     return _process(data, 'purify', data)
  8.  
  9.  
  10. def scrape(data):
  11.     return _process(data, 'scrape', '')
  12.  
  13.  
  14. def _process(data, fkey, default):
  15.     if data is None:
  16.         return ''
  17.     
  18.     processed = None
  19.     for funcs in FUNCS:
  20.         process = funcs[fkey]
  21.         processed = process(data)
  22.         if processed is not None:
  23.             break
  24.             continue
  25.     
  26.     if processed is None:
  27.         processed = default
  28.     
  29.     return processed
  30.  
  31. FEEDBURNER_AD_PATTERN = re.compile('\n    <p>                                                               # <p>\n    <a\\shref="http://feeds\\.feedburner\\.com/~a/[^"]*">                # <a href="...">\n    <img\\ssrc="http://feeds\\.feedburner\\.com/~a/[^"]*"\\sborder="0">   # <img src="..." border="0">\n    </img>                                                            # </img>\n    </a>                                                              # </a>\n    </p>                                                              # </p>\n    ', re.VERBOSE)
  32.  
  33. def _tryPurifyingFeedBurner(data):
  34.     if FEEDBURNER_AD_PATTERN.search(data):
  35.         return FEEDBURNER_AD_PATTERN.sub('', data)
  36.     
  37.  
  38.  
  39. def _tryScrapingFeedBurner(data):
  40.     match = FEEDBURNER_AD_PATTERN.search(data)
  41.     if match is not None:
  42.         return match.group(0)
  43.     
  44.  
  45. FUNCS = [
  46.     {
  47.         'purify': _tryPurifyingFeedBurner,
  48.         'scrape': _tryScrapingFeedBurner }]
  49.